import { defineStore } from 'pinia'

export const useSettings = defineStore('settingsId', {
  state() {
    return {
      lyricBg: 'rhythm' as 'rgb' | 'rhythm',
      theme: 'light' as 'light' | 'dark' // 添加主题状态
    }
  },
  actions: {
    // 初始化主题
    initTheme() {
      // 优先从本地存储读取主题
      const savedTheme = localStorage.getItem('theme')
      if (savedTheme) {
        this.theme = savedTheme as 'light' | 'dark'
      }
      // 应用主题
      document.documentElement.setAttribute('data-theme', this.theme)
    },
    // 切换主题
    toggleTheme() {
      this.theme = this.theme === 'light' ? 'dark' : 'light'
      document.documentElement.setAttribute('data-theme', this.theme)
      // 保存主题到本地存储
      localStorage.setItem('theme', this.theme)
    }
  }
})
